package com.fuyu.common.handle;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.fuyu.common.web.controller.BaseController;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

@Component
public class MyMetaObjectHandler extends BaseController implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        String userId = getUserId();
        if (metaObject.hasGetter("createBy")) {
            setFieldValByName("createBy", userId, metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        String userId = getUserId();
        if (metaObject.hasGetter("updateBy")) {
            setFieldValByName("updateBy", userId, metaObject);
        }
    }
}